package com.jc.order.service.impl;

import com.jc.order.domain.JcInsuranceRateSetting;
import com.jc.order.dto.JcInsuranceRateSettingDTO;
import com.jc.order.mapper.JcInsuranceRateSettingMapper;
import com.jc.order.service.JcInsuranceRateSettingService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;

@Service
public class JcInsuranceRateSettingServiceImpl implements JcInsuranceRateSettingService {

    @Resource
    private JcInsuranceRateSettingMapper jcInsuranceRateSettingMapper;


    @Override
    public JcInsuranceRateSettingDTO selectInsuranceRateSetting(JcInsuranceRateSettingDTO dto) {
        JcInsuranceRateSettingDTO rateSettingDTO = null;

        Example example = new Example(JcInsuranceRateSetting.class, true, true);
        Example.Criteria criteria = example.createCriteria()
                .andEqualTo("tenId", dto.getTenId())
                .andEqualTo("insuranceType", dto.getInsuranceType())
                .andEqualTo("versionType", dto.getVersionType())
                .andEqualTo("deleted", false);
        if ("1".equalsIgnoreCase(dto.getInsuranceType().toString())) {
            criteria.andEqualTo("transportType", dto.getTransportType())
                    .andEqualTo("dispatchType", dto.getDispatchType())
                    .andEqualTo("shelfGuarantee", dto.getShelfGuarantee());
        }
        List<JcInsuranceRateSetting> list = jcInsuranceRateSettingMapper.selectByExample(example);
        // 返回一条 数据才是正确的；
        if (list != null && list.size() == 1) {
            rateSettingDTO = new JcInsuranceRateSettingDTO();
            BeanUtils.copyProperties(list.get(0), rateSettingDTO);
        }
        return rateSettingDTO;
    }
}
